package com.jmz.apt.api.service.tpl;

import com.jmz.apt.api.dao.TygpDao;
import com.jmz.apt.api.entity.dbEntity.JmzAdminUser;
import com.jmz.apt.api.entity.dbEntity.TimeTygp;
import com.jmz.apt.api.entity.dbEntity.TimeTygpGroup;
import com.jmz.apt.api.enums.ResponseCode;
import com.jmz.apt.api.exception.BusinessException;
import com.jmz.apt.api.message.request.Condition;
import com.jmz.apt.api.message.request.Query;
import com.jmz.apt.api.message.request.RequestMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Tygp {

    @Autowired
    TygpDao tygpDao;

    public List<TimeTygp> findAllTimeTplLst(RequestMessage requestMessage) throws DataAccessException {
        List<Condition> condition = requestMessage.getMessage().getBody().getQuery().getCondition();
        Query query = requestMessage.getMessage().getBody().getQuery();
        List<TimeTygp> timeTygpLst = tygpDao.findTygps("*",condition,query);
        return timeTygpLst;
    }

    public Integer  saveTpl(TimeTygp timeTygp) throws DataAccessException {
        Integer TygpId =0;
        TygpId = tygpDao.saveTygp(timeTygp);
        return TygpId;
    }

    public Boolean updateTpl(TimeTygp timeTygp) throws DataAccessException{
        TimeTygp cond = new TimeTygp();
        if(null == timeTygp.getId()){
            throw new BusinessException(ResponseCode.DB_LOSE_PARM.getCode(),
                    ResponseCode.DB_LOSE_PARM.getDesc());
        }
        cond.setId(timeTygp.getId());
        TimeTygp tpl = tygpDao.findTygpOne(cond);
        if(tpl == null) {
            return false;
        }
        tygpDao.updateTpl(timeTygp);
        return true;
    }

}
